/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : airplane.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-1-20 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/

#include <stdio.h>
#include "airplane.h"
#include "control_tower_base.h"

#define PLANE_LOGI(fmt, args...) printf(fmt, ##args)
#define PLANE_LOGD(fmt, args...) printf("%d PLANE D: " fmt, __LINE__, ##args)
#define PLANE_LOGW(fmt, args...) printf("%d PLANE W: " fmt, __LINE__, ##args)
#define PLANE_LOGE(fmt, args...) printf("%d PLANE E: " fmt, __LINE__, ##args)

// ------------------   AirBusA319   ------------------
CAirBusA319::CAirBusA319()
{
    pmMeditor = NULL;
}

CAirBusA319::~CAirBusA319()
{
    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return;
    }

    pmMeditor->UnRegister(mIdForMediator);
}

void CAirBusA319::SetMediator(CTowerMediatorBase *meditor)
{
    if (!meditor) {
        PLANE_LOGE("meditor is NULL!\n");
    }

    pmMeditor = meditor;
    mIdForMediator = pmMeditor->Register(this);
}

int CAirBusA319::Notify(void *msg)
{
    int ret = -1;

    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return -1;
    }

    ret = pmMeditor->Receive(mIdForMediator, msg);

    return ret;
}

int CAirBusA319::Receive(void *msg)
{
    int ret = 0;

    PLANE_LOGI("[CAirBusA319] Recv: %s\n", (char *)msg);

    return ret;
}

// ------------------   CBoeing737   ------------------
CBoeing737::CBoeing737()
{
    pmMeditor = NULL;
}

CBoeing737::~CBoeing737()
{
    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return;
    }

    pmMeditor->UnRegister(mIdForMediator);
}

void CBoeing737::SetMediator(CTowerMediatorBase *meditor)
{
    if (!meditor) {
        PLANE_LOGE("meditor is NULL!\n");
    }

    pmMeditor = meditor;
    mIdForMediator = pmMeditor->Register(this);
}

int CBoeing737::Notify(void *msg)
{
    int ret = -1;

    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return -1;
    }

    ret = pmMeditor->Receive(mIdForMediator, msg);

    return ret;
}

int CBoeing737::Receive(void *msg)
{
    int ret = 0;

    PLANE_LOGI("[CBoeing737] Recv: %s\n", (char *)msg);

    return ret;
}

// ------------------   CComacC919   ------------------
CComacC919::CComacC919()
{
    pmMeditor = NULL;
}

CComacC919::~CComacC919()
{
    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return;
    }

    pmMeditor->UnRegister(mIdForMediator);
}

void CComacC919::SetMediator(CTowerMediatorBase *meditor)
{
    if (!meditor) {
        PLANE_LOGE("meditor is NULL!\n");
    }

    pmMeditor = meditor;
    mIdForMediator = pmMeditor->Register(this);
}

int CComacC919::Notify(void *msg)
{
    int ret = -1;

    if (!pmMeditor) {
        PLANE_LOGE("pmMeditor is NULL!\n");
        return -1;
    }

    ret = pmMeditor->Receive(mIdForMediator, msg);

    return ret;
}

int CComacC919::Receive(void *msg)
{
    int ret = 0;

    PLANE_LOGI("[CComacC919] Recv: %s\n", (char *)msg);

    return ret;
}

